import SwiftUI

struct NameOnboardingSheet: View {
    @AppStorage("userName") private var userName: String = ""
    var onDone: () -> Void
    @State private var temp: String = ""
    
    var body: some View {
        VStack(spacing: 16) {
            Capsule().fill(.secondary.opacity(0.4)).frame(width: 40, height: 5).padding(.top, 8)
            Text("欢迎使用")
                .font(.headline)
            Text("请输入你的姓名，用于导出的数据文件命名")
                .font(.footnote)
                .foregroundColor(.secondary)
            TextField("姓名", text: $temp)
                .textFieldStyle(.roundedBorder)
                .textInputAutocapitalization(.words)
            Button("保存") {
                let t = temp.trimmingCharacters(in: .whitespacesAndNewlines)
                if !t.isEmpty {
                    userName = t
                    onDone()
                }
            }
            .buttonStyle(.borderedProminent)
            Spacer(minLength: 0)
        }
        .padding(20)
        .onAppear { temp = userName }
    }
}
